{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:33.677672Z",
     "start_time": "2025-10-21T10:40:23.879848Z"
    }
   },
   "source": "import torch",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:33.692463Z",
     "start_time": "2025-10-21T10:40:33.685421Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "np1 = np.arange(18).reshape(3,2,3)\n",
    "np1"
   ],
   "id": "faca4695dce427a9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1,  2],\n",
       "        [ 3,  4,  5]],\n",
       "\n",
       "       [[ 6,  7,  8],\n",
       "        [ 9, 10, 11]],\n",
       "\n",
       "       [[12, 13, 14],\n",
       "        [15, 16, 17]]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:33.722913Z",
     "start_time": "2025-10-21T10:40:33.713460Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t1 = torch.tensor([[1,2],[3,4],[5,6],[7,8],[9,10]])\n",
    "t1"
   ],
   "id": "8a7ecddfa8daf6e1",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 1,  2],\n",
       "        [ 3,  4],\n",
       "        [ 5,  6],\n",
       "        [ 7,  8],\n",
       "        [ 9, 10]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:33.781118Z",
     "start_time": "2025-10-21T10:40:33.774208Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t2 = torch.from_numpy(np1)\n",
    "t2"
   ],
   "id": "f936c6b73728cb73",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 0,  1,  2],\n",
       "         [ 3,  4,  5]],\n",
       "\n",
       "        [[ 6,  7,  8],\n",
       "         [ 9, 10, 11]],\n",
       "\n",
       "        [[12, 13, 14],\n",
       "         [15, 16, 17]]], dtype=torch.int32)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:34.024639Z",
     "start_time": "2025-10-21T10:40:34.017796Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t3 = torch.zeros(3,2,3) # 创建全0d的torch\n",
    "t3"
   ],
   "id": "c6ab200b5ee5bcbe",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0., 0., 0.],\n",
       "         [0., 0., 0.]],\n",
       "\n",
       "        [[0., 0., 0.],\n",
       "         [0., 0., 0.]],\n",
       "\n",
       "        [[0., 0., 0.],\n",
       "         [0., 0., 0.]]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:34.212246Z",
     "start_time": "2025-10-21T10:40:34.206212Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t3 = torch.ones(3,2,3)\n",
    "t3"
   ],
   "id": "165592af427d7acd",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[1., 1., 1.],\n",
       "         [1., 1., 1.]],\n",
       "\n",
       "        [[1., 1., 1.],\n",
       "         [1., 1., 1.]],\n",
       "\n",
       "        [[1., 1., 1.],\n",
       "         [1., 1., 1.]]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:34.355115Z",
     "start_time": "2025-10-21T10:40:34.349651Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t5 = torch.rand(3,2,4) # 标准正态分布的数\n",
    "t5"
   ],
   "id": "346d87d30bc5d312",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.9234, 0.4299, 0.3772, 0.4138],\n",
       "         [0.8227, 0.5177, 0.3477, 0.1282]],\n",
       "\n",
       "        [[0.4333, 0.4811, 0.4379, 0.3166],\n",
       "         [0.5176, 0.7597, 0.7253, 0.8080]],\n",
       "\n",
       "        [[0.7650, 0.1669, 0.0226, 0.0461],\n",
       "         [0.1056, 0.3971, 0.5546, 0.1546]]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:34.428710Z",
     "start_time": "2025-10-21T10:40:34.422698Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t6 = torch.randn(3,2,4)\n",
    "t6"
   ],
   "id": "53b4c394102f7e9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 1.1434,  1.3893, -0.7997,  2.3157],\n",
       "         [ 0.3633,  0.2405,  0.4438,  0.2322]],\n",
       "\n",
       "        [[ 3.3619, -0.8861, -0.6076, -0.2701],\n",
       "         [ 1.1296, -1.5402,  0.7372,  1.5233]],\n",
       "\n",
       "        [[ 0.2685, -1.1615, -0.1041,  0.8898],\n",
       "         [-1.3461, -0.0390,  0.6198,  0.4831]]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:40:57.462135Z",
     "start_time": "2025-10-21T10:40:57.450475Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t7 = torch.normal(100,0.3,(3,2,1))\n",
    "t7\n"
   ],
   "id": "cb5b18a51afcdaf",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[100.1553],\n",
       "         [ 99.9527]],\n",
       "\n",
       "        [[ 99.8646],\n",
       "         [ 99.7704]],\n",
       "\n",
       "        [[ 99.6027],\n",
       "         [ 99.9457]]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:46:06.968612Z",
     "start_time": "2025-10-21T10:46:06.961319Z"
    }
   },
   "cell_type": "code",
   "source": "t7.shape",
   "id": "a7b4a883bdc6e630",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([3, 2, 1])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T10:48:40.533451Z",
     "start_time": "2025-10-21T10:48:40.524257Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t7 = torch.permute(t6,(2,0,1)) # 根据索引\n",
    "t7"
   ],
   "id": "5443018d90b25066",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 1.1434,  0.3633],\n",
       "         [ 3.3619,  1.1296],\n",
       "         [ 0.2685, -1.3461]],\n",
       "\n",
       "        [[ 1.3893,  0.2405],\n",
       "         [-0.8861, -1.5402],\n",
       "         [-1.1615, -0.0390]],\n",
       "\n",
       "        [[-0.7997,  0.4438],\n",
       "         [-0.6076,  0.7372],\n",
       "         [-0.1041,  0.6198]],\n",
       "\n",
       "        [[ 2.3157,  0.2322],\n",
       "         [-0.2701,  1.5233],\n",
       "         [ 0.8898,  0.4831]]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
